home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
me_cd25.zip
/
MC2MUTT.ZIP
/
SORT.MUT
< prev
next >
Wrap
Lisp/Scheme
|
1992-11-09
|
1KB
|
51 lines
(defun
sort (array int list-to-sort 1)(int n) ; shell sort an array of n ints
{
(int gap i j t k)
(gap (/ n 2))
(while (> gap 0)
{
(i gap)
(while (< i n)
{
(j (- i gap))
(while (and (>= j 0) (> (list-to-sort j)(list-to-sort (+ j gap))))
{
(k (+ j gap))(t (list-to-sort j))
(list-to-sort j (list-to-sort k))(list-to-sort k t)
(-= j gap)
})
(+= i 1)
})
(/= gap 2)
})
}
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;; test ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(const NUMBER 0x03)
(include random.mut)
(array int list-to-sort 501) (int n j)
(defun MAIN
{
(n (convert-to NUMBER (ask "n = ")))
;(srand 123)
(for (j 0) (< j n)(+= j 1) (list-to-sort j (rand)))
(for (j 0)(< j n)(+= j 1) (msg "Random list[" j "] = " (list-to-sort j)))
(sort list-to-sort n)
(msg "--------------------------")
(for (j 0)(< j n)(+= j 1) (msg "Sorted list[" j "] = " (list-to-sort j)))
})